<?php
/*
 *  @author Nicolas Genevaux
 * (c)nige 2008
 */
	include_once($RACINE.'inc/fct.utils.php');
	include_once($RACINE.'inc/fct.basedonnee.php');
	include_once($RACINE.'inc/sql.exercice.php');
	include_once($RACINE.'inc/sql.exercicechoix.php');
	include_once($RACINE.'inc/sql.inscrit.php');
	include_once($RACINE.'inc/var.pages.php');
	$_SESSION['matiere'] = $_POST['identifiantmatiere'];
	$_SESSION['question'] = $_POST['question'];
	$_SESSION['reponse1'] = $_POST['reponse1'];
	$_SESSION['reponse2'] = $_POST['reponse2'];
	$_SESSION['reponse3'] = $_POST['reponse3'];
	$_SESSION['reponse4'] = $_POST['reponse4'];
	$_SESSION['reponse'] = $_POST['reponse'];
	if($_POST['identifiantmatiere']=='choix' || $_POST['question']=='' || $_POST['reponse']=='') {
		redirect($PAGE_AJOUT_QUESTION.'?errcode=1');
	}
	else {
		doSQL($EXERCICE_INSERT,array(0=>"'".$_POST['identifiantinscrit']."'",1=>"'".$_POST['identifiantmatiere']."'",2=>"'".$_POST['question']."'"));
		$idEx = getLastInsertID();
		if($idEx==0) {
			redirect($PAGE_AJOUT_QUESTION.'?errcode=0');
		}
		else {
			$idconn = $_SESSION['ID_CONECT'];
			$_SESSION = array();
			$_SESSION['ID_CONECT'] = $idconn;
			doSQL($EXERCICECHOIX_INSERT,array(0=>"'".$idEx."'",1=>"'".$_POST['reponse1']."'",2=>($_POST['reponse']==1)? "'O'" : "'N'"));
			doSQL($EXERCICECHOIX_INSERT,array(0=>"'".$idEx."'",1=>"'".$_POST['reponse2']."'",2=>($_POST['reponse']==2)? "'O'" : "'N'"));
			doSQL($EXERCICECHOIX_INSERT,array(0=>"'".$idEx."'",1=>"'".$_POST['reponse3']."'",2=>($_POST['reponse']==3)? "'O'" : "'N'"));
			doSQL($EXERCICECHOIX_INSERT,array(0=>"'".$idEx."'",1=>"'".$_POST['reponse4']."'",2=>($_POST['reponse']==4)? "'O'" : "'N'"));
			$IDMATIERE = $_POST['identifiantmatiere'];
			include($RACINE.'inc/var.points.php');
			doSQL($INSCRIT_POINTS,array(0=>$_SESSION['ID_CONECT'],1=>$QUESTIONS));
			redirect($PAGE_AJOUT_QUESTION.'?ok=1');
		}
	}
?>
